package com.ecr.hub;

import java.io.PrintWriter;
import java.io.StringWriter;

import com.ecr.hub.model.enumeration.HubErrorLevel;

public class ApplicationException extends Exception {

	private static final long serialVersionUID = 1L;
	private HubErrorLevel errorLevel;

	public ApplicationException(String errorMsg) {
		super(errorMsg);
	}

	public ApplicationException(Exception e) {
		super(e);
	}

	public ApplicationException(String errorMsg, HubErrorLevel errorLevel) {
		super(errorMsg);
		this.errorLevel = errorLevel;
	}

	public ApplicationException(Exception e, HubErrorLevel errorLevel) {
		super(e);
		this.errorLevel = errorLevel;
	}

	public HubErrorLevel getErrorLevel() {
		return errorLevel;
	}

	public void setErrorLevel(HubErrorLevel errorLevel) {
		this.errorLevel = errorLevel;
	}

	/**
	 * Récupération de la pile d'une exception dans une string.
	 */
	public static String getStackTraceToString(Exception e) {

		StringWriter in = new StringWriter();
		PrintWriter ps = new PrintWriter(in);
		e.printStackTrace(ps);
		return in.getBuffer().toString();
	}
}
